import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/images.dart';

import '../../../../hj_utils/widget_utils.dart';
import 'ai_girl_friend_logic.dart';

// Ai女友
class AIGrilFriendPage extends StatefulWidget {
  const AIGrilFriendPage({super.key});

  @override
  State<AIGrilFriendPage> createState() => _AIGrilFriendPageState();
}

class _AIGrilFriendPageState extends State<AIGrilFriendPage> with RouteAware {
  AIGrilFriendLogic logic = Get.put(AIGrilFriendLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        alignment: Alignment.center,
        children: [
          Image.asset(
            'ai_girl_friend_bg.webp'.aiPath,
            fit: BoxFit.fill,
            width: Get.width,
            height: Get.height,
          ),
          Positioned(
            bottom: 125,
            left: 10,
            right: 10,
            child: GestureDetector(
              onTap: () => logic.onFetchJumpUrl(),
              child: Image.asset(
                'ai_girl_friend_btn.webp'.aiPath,
              ),
            ),
          ),
          Positioned(
            top: 0,
            height: 101,
            child: Stack(
              children: [
                Image.asset(
                  'ai_girl_friend_top.webp'.aiPath,
                  width: Get.width,
                  fit: BoxFit.fitWidth,
                ),
                _buildBanlance(),
              ],
            ),
          ),
          Positioned.fill(
            child: Obx(() => logic.open.value
                ? Container()
                : Stack(
                    children: [
                      Container(
                        color: Colors.black.withOpacity(.75),
                        child: Center(
                            child: Obx(
                          () => Text(
                            logic.tips.value,
                            style: textStyle(17, Colors.white, FontWeight.w500),
                          ),
                        )),
                      ),
                      Positioned(
                        left: 10,
                        top: 60,
                        child: GestureDetector(
                          child: GestureDetector(
                            onTap: () => Get.back(),
                            child: const Icon(Icons.arrow_back_ios, size: 24, color: Colors.white),
                          ),
                        ),
                      )
                    ],
                  )),
          ),
        ],
      ),
    );
  }

  _buildBanlance() {
    return Positioned(
      left: 10,
      right: 10,
      bottom: 14,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          GestureDetector(
            child: GestureDetector(
              onTap: () => Get.back(),
              child: const Icon(Icons.arrow_back_ios, size: 24, color: Colors.white),
            ),
          ),
          Container(
            padding: EdgeInsets.all(1),
            decoration: BoxDecoration(
              color: Colors.black,
              borderRadius: BorderRadius.circular(100),
              border: Border.all(color: Color(0xff2A5298)),
            ),
            child: Row(
              children: [
                const SizedBox(width: 12),
                GetBuilder<AIGrilFriendLogic>(
                  id: 'balance',
                  builder: (_) {
                    if (_.balanceModel != null) {
                      return Text(
                        '积分:${_.balanceModel?.balance ?? 0}',
                        style: textStyle(18, Colors.white, FontWeight.w400),
                      );
                    } else {
                      return const SizedBox(
                        width: 22,
                        child: CupertinoActivityIndicator(
                          color: Colors.white,
                          radius: 8,
                        ),
                      );
                    }
                  },
                ),
                const SizedBox(width: 10),
                GestureDetector(
                  onTap: () => logic.onRechargeBottomSheet(),
                  child: Image.asset(
                    'ai_girl_friend_topup.webp'.aiPath,
                    width: 76,
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
